package util;

import java.util.Scanner;
public class InputUtils {
    // 创建一个静态的Scanner对象，用于控制台输入
    private static Scanner scanner = new Scanner(System.in);
    public static int inputInt(String prompt) {//静态方法，直接通过类名调用
        System.out.print(prompt);
        while (!scanner.hasNextInt()) {
            System.out.println("输入无效，请输入一个整数！");
            System.out.print(prompt);
            scanner.next();
        }
        return scanner.nextInt();
    }

    public static String inputString(String prompt) {
        System.out.print(prompt);
        scanner.nextLine(); // 清除缓冲区
        return scanner.nextLine();
    }

    public static boolean confirm(String prompt) {
        System.out.print(prompt + " (Y/N): ");
        String response = scanner.next().trim().toUpperCase();
        return response.equals("Y");
    }
}
